package com.itfreer.power.service.power.strategy;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.form.dictionary.DictionaryManage;
import com.itfreer.form.dictionary.base.DictionaryItem;

/**
 * 菜单权限数据提供接口
 */
@Component("MemoryMenusJurisdictionDataProvide")
public class MemoryMenusJurisdictionDataProvide implements MenusJurisdictionDataProvide {

	@Autowired
	private DictionaryManage dictionaryManage;

	private static final String menuDic = "p_menu_jurisdiction";

	@Override
	public List<String> getMenus(List<String> menusIDs, String serviceId) {
		if (menusIDs == null || menusIDs.size() <= 0) {
			return null;
		}
		List<String> result = new ArrayList<String>();
		for (String menusID : menusIDs) {
			DictionaryItem item = dictionaryManage.getDictionary(menuDic, menusID);
			if (item != null && item.getOther().get("registerService").toString().equals(serviceId)) {
				result.add(item.getCode());
			}
		}
		return result;
	}

	@Override
	public List<String> getUrls(List<String> menusIDs, String serviceId) {
		if (menusIDs == null || menusIDs.size() <= 0) {
			return null;
		}
		List<String> result = new ArrayList<String>();
		for (String menusID : menusIDs) {
			DictionaryItem item = dictionaryManage.getDictionary(menuDic, menusID);
			if (item != null && item.getOther().get("registerService").toString().equals(serviceId)) {
				if (item.getOther().containsKey("urls") && item.getOther().get("urls") != null) {
					result.add(item.getOther().get("urls").toString());
				}
			}
		}
		return result;
	}

}
